package com.example.subscriber.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @project: kaoshi
 * @description:
 * @author: cjq
 * @create: 2022-11-06 21:04
 **/
@Configuration
public class SendMessagesConfig {
    public static final String CJQ_SEND_MESSAGE_EXCHANGE_NAME = "cjq.send.message.exchange.name";
    public static final String CJQ_SEND_MESSAGE_QUEUE_NAME = "cjq.send.message.queue.name";
    public static final String CJQ_SEND_MESSAGE_ROUTING_KEY_NAME = "cjq.send.message.routing.key.name";

    @Bean
    DirectExchange sendMessagesExchange() {
        return new DirectExchange(CJQ_SEND_MESSAGE_EXCHANGE_NAME);
    }

    //配置队列
    @Bean
    Queue sendMessagesQueue() {
        return new Queue(CJQ_SEND_MESSAGE_QUEUE_NAME);
    }

    //绑定队列到交换机
    @Bean
    Binding oderMessagesBinding() {
        return BindingBuilder.bind(sendMessagesQueue()).to(sendMessagesExchange()).with(CJQ_SEND_MESSAGE_ROUTING_KEY_NAME);
    }
}
